package SmallChange;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @Package: SmallChange
 * @ClassName: SmallChangeSys
 * @Author: x2606
 * @CreateTime: 2022/3/4 13:24
 * @Description: 零钱通面向过程版本
 */

public class SmallChangeSys {
    public static void main(String[] args) {
        //菜单显示循环变量
        Boolean loop = true;

        //接受输入选项
        Scanner scanner=new Scanner(System.in);
        String key="";

        //根据需求定义变量

        //使用字符串拼接来实现明细
        String detail="-----------零钱明细-----------";

        double money=0;
        double balance=0;

        //java.util.Date表示日期
        Date date=null;
        //java.text.SimpleDateFormat 用于处理时间格式
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm");

        String name=null;

        String shutdown="";

        do{
            System.out.println("\n============零钱通系统============");
            System.out.println("\t\t\t1.零钱通明细");
            System.out.println("\t\t\t2.存     入");
            System.out.println("\t\t\t3.消     费");
            System.out.println("\t\t\t4.退     出");
            System.out.print("请输入选项（1-4）：");
            key=scanner.next();

            switch (key){
                case "1":
                    System.out.println(detail);
                    break;
                case "2":
                    System.out.print("收益入账金额：");
                    money=scanner.nextDouble();
                    if (money<=0){
                        System.out.println("收入金额需要大于0！");
                        break;
                    }
                    balance+=money;

                    //获取当前时间
                    date=new Date();
                    detail+="\n收益\t+"+money+"\t"+sdf.format(date)+"\t余额："+balance;
                    break;
                case "3":
                    System.out.print("消费名称：");
                    name=scanner.next();
                    System.out.print("消费金额：");
                    money=scanner.nextDouble();
                    if (money>balance||money<=0){
                        System.out.println("消费金额需要大于0或者小于等于余额！");
                        break;
                    }
                    balance-=money;
                    date=new Date();
                    detail+="\n"+name+"\t-"+money+"\t"+sdf.format(date)+"\t余额："+balance;
                    break;
                case "4":
                    do{
                        System.out.print("你确定要退出吗？y/n:");
                        shutdown=scanner.next();
                        if (shutdown.equals("y")){
                            loop=false;
                            break;
                        }else if(shutdown.equals("n")) {
                            break;
                        }else {
                            System.out.println("输入错误，请重新输入！");
                        }
                    }while (true);
                    break;
                default:
                    System.out.println("输入的选项错误，请重新输入：");
            }
        }while (loop);
    }
}
